from locust import HttpLocust, TaskSet, task


# 定义用户行为
# 继承自TaskSet
# on_start为第一次call的函数
# @task为随机call的地址, 1,2代表call的比例
# WebsiteUser定义call的行为, 定义call的地址, 每次call的间隔时间, 为随机1s到5s之间

class WebsiteTasks(TaskSet):
    def on_start(self):
        self.client.post("/account/info", {
            "app": "BIXIN",
            "userId": "d5dae7ea3a75c73af68d5c4f4c2d4035"
        })

    @task(2)
    def index(self):
        self.client.get("/")

    @task(1)
    def about(self):
        self.client.get("/about/")


class WebsiteUser(HttpLocust):
    task_set = BixinApiTasks
    host = "http://10.28.28.132:10011"
    min_wait = 1000
    max_wait = 3000


class BixinApiTasks(TaskSet):

    @task
    def accountinfo(self):
        self.client.post("/account/info", {
            "app": "BIXIN",
            "userId": "d5dae7ea3a75c73af68d5c4f4c2d4035"
        })

    # @task(2)
    # def index(self):
    #     self.client.get("/")
    #
    # @task(1)
    # def about(self):
    #     self.client.get("/about/")